<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var str1 = 'hello'
      console.log(str1) //hello
      // length 只读
      console.log(str1.length) //5
      // 索引【下标】 只读
      console.log(str1[1]) //e
      // 遍历
      for (var i = 0; i < str1.length; i++) {
        console.log(i, str1[i]) // 0 'h' 1 'e' 2 'l' 3 'l' 4 '0'
      }

      var str2 = new String('hello')
      console.log(str2) //String {'hello'}

      // 案例：统计字母出现的次数
      var str3 = 'abcabcab'
      var obj = {}
      for (var i = 0; i < str3.length; i++) {
        var key = str3[i]
        if (obj[key] === undefined) {
          obj[key] = 1
        } else {
          obj[key]++
        }
      }
      console.log(obj) //{a: 3, b: 3, c: 2}
    </script>
  </body>
</html>
